﻿<%@ Page Language="C#" MasterPageFile="AdminSite.master" AutoEventWireup="true" CodeFile="QuanLyHinhAnh.aspx.cs"
    Inherits="QuanLyHinhAnh" %>

<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript" src="../js/jquery.js"></script>
    <script type='text/javascript' language='javascript' src="../js/jquery.lightbox-0.5.js"></script>
    <link href="../Css/jquery.lightbox-0.5.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $('#gallery a').lightBox({
                imageLoading: '../images/web/lightbox-ico-loading.gif',
                imageBtnClose: '../images/web/close.gif',
                imageBtnPrev: '../images/web/lightbox-btn-prev.gif',
                imageBtnNext: '../images/web/lightbox-btn-next.gif',
                imageBlank: '../images/web/lightbox-blank.gif'
            }
            );

        });
        
    </script>
    <style type="text/css">
        .style1
        {
            width: 146px;
        }
        .style2
        {
            height: 72px;
        }
        .style3
        {
            height: 59px;
        }
        .style4
        {
            height: 16px;
        }
        .style5
        {
        }
        .style6
        {
            height: 59px;
            width: 88px;
        }
        .style7
        {
            width: 170px;
        }
        .style8
        {
            width: 86px;
        }
        .style9
        {
            width: 257px;
        }
        .style10
        {
            width: 59px;
        }
        #btnAdd
        {
            width: 155px;
        }
    </style>
    <script type="text/javascript">
        function AddFileUploadControl() {
            for (i = 0; i < 4; i++) { //add 3 line at once
                if (!document.getElementById || !document.createElement) {
                    alert("Trình duyệt của bạn không hổ trợ upload nhiều ảnh.");
                    return false;
                }
                var uploadArea = document.getElementById("content");
                if (!uploadArea)
                    return;
                var newLine = document.createElement("br");
                uploadArea.appendChild(newLine);
                newLine.setAttribute("flag", "1");
                var newFile = document.createElement("input");
                newFile.type = "file";
                newFile.size = "60";
                if (!AddFileUploadControl.lastAssignedId)
                    AddFileUploadControl.lastAssignedId = 1000;
                newFile.setAttribute("id", "dynamic" + AddFileUploadControl.lastAssignedId);
                newFile.setAttribute("name", "dynamic" + AddFileUploadControl.lastAssignedId);
                newLine.setAttribute("flag", "1");
                uploadArea.appendChild(newFile);
                AddFileUploadControl.lastAssignedId++;
            }
        }
        function showAddAlbum() {
            document.getElementById("divAddAlbum").style.display = "block";
            return false;
        }
        function closeAddAlbum() {
            document.getElementById("divAddAlbum").style.display = "none";
            var uploadArea = document.getElementById("content");
            var i = uploadArea.childNodes.length - 1;
            while (i >= 15) {
                var node = uploadArea.childNodes.item(i);
                uploadArea.removeChild(node);
                i--;
            }
            return false;
        }
        function beforeSaveImage() {
            var content = document.getElementById("content");
            content.style.backgroundImage = "url(../images/web/loading.gif)";
            content.style.backgroundRepeat = "no-repeat";
            content.style.backgroundPosition = "center";
        }
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2 align="center" style="font-weight: bold">
        <asp:Label ID="lblTitle" runat="server" Font-Bold="True">ALBUM ẢNH</asp:Label>
    </h2>
    <table style="width: 100%">
        <tr>
            <td class="style2">
                <table>
                    <tr>
                        <td class="style5" colspan="6">
                            <asp:ValidationSummary ID="BaiVietValidationSummary" runat="server" CssClass="failureNotification"
                                ValidationGroup="AlbumValidationGroup" DisplayMode="List" />
                        </td>
                    </tr>
                    <tr>
                        <td class="style5">
                            Ngày tạo:
                        </td>
                        <td class="style7">
                            <asp:Label ID="lblNgayTao" runat="server" Font-Bold="True"></asp:Label>
                        </td>
                        <td class="style8">
                            Người tạo:
                        </td>
                        <td class="style9">
                            <asp:Label ID="lblNguoiTao" runat="server" Font-Bold="True"></asp:Label>
                        </td>
                        <td class="style10">
                            Số ảnh:
                        </td>
                        <td class="style1">
                            <asp:Label ID="lblSoAnh" runat="server" Font-Bold="True"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="style5">
                            Tên Album
                        </td>
                        <td colspan="5">
                            <asp:TextBox ID="txtTenAlbum" runat="server" Font-Bold="True" Width="798px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="TenAlbumRequired" runat="server" ControlToValidate="txtTenAlbum"
                                CssClass="failureNotification" ErrorMessage="* Bạn chưa nhập tên album" ToolTip="Vui lòng nhập tên album."
                                ValidationGroup="AlbumValidationGroup">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td class="style6" valign="top">
                            Mô tả Album:
                        </td>
                        <td colspan="5" class="style3">
                            <CKEditor:CKEditorControl ID="txtMoTa" runat="server" Height="81px" Width="801px"></CKEditor:CKEditorControl>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" class="style4" colspan="6" valign="top">
                            <asp:Button CssClass="btnadmin" ID="btnSave" runat="server" Text="Lưu album" Width="134px"
                                OnClick="btnSave_Click" ValidationGroup="AlbumValidationGroup" />
                            <input id="btnAdd" class="btnadmin" type="button" value="Thêm ảnh vào album" onclick="showAddAlbum()"
                                style="<%= IsVisible()%>" />
                            <asp:Button CssClass="btnadmin" ID="btnCreatNew" runat="server" Text="Tạo mới album"
                                Width="129px" OnClick="btnCreatNew_Click" />
                            <asp:Button CssClass="btnadmin" ID="btnDelete" runat="server" OnClick="btnDelete_Click"
                                Text="Xóa album" Width="121px" OnClientClick="return confirm('Xóa album này sẽ xóa hết các hình ảnh của album.\nBạn có chắc là muốn xóa?');" />
                            <asp:Button CssClass="btnadmin" ID="btnBack" runat="server" Text="Quản lý album"
                                OnClick="btnBack_Click" />
                            <asp:HiddenField ID="keyField" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td align="center" class="style4" colspan="6" valign="top">
                            <asp:Label ID="lblNoctice" runat="server" Font-Bold="True" ForeColor="Red" Visible="False"></asp:Label>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%">
                    <tr>
                        <td id="gallery">
                            <asp:DataList ID="listImage" RepeatLayout="Table" RepeatColumns="4" RepeatDirection="Horizontal"
                                runat="server" Height="518px">
                                <ItemTemplate>
                                    <fieldset class="btn_img">
                                        <table cellpadding="2" cellspacing="0" border="0" width="100%">
                                            <tr>
                                                <td align="center">
                                                    <a href='<%# Eval("URL_IMAGE")%>' title='Xem ảnh'>
                                                        <asp:Image ID="img_first" runat="server" Width="160" Height="160" class="img_border"
                                                            ImageUrl='<%# Eval("URL_IMAGE")%>' /></a>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" style="font-size: 11px">
                                                    <%# Eval("IMAGE_NAME")%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" style="font-size: 11px">
                                                    Thêm bới: <b>
                                                        <%#Eval("NGUOI_TAO") %>
                                                        <br />
                                                        Ngày thêm:
                                                        <%#Eval("NGAY_TAO","{0:dd/MM/yyyy HH:mm:ss }") %>
                                                    </b>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" valign="middle" style="cursor: hand;">
                                                    <asp:Button ID="btnAnhBia" Text="Đặt làm ảnh bìa" CommandName="cmdAnhBia" runat="server"
                                                        CommandArgument='<%# Eval("ID") %>' OnClick="btnAnhBia_cLick" CssClass="btn_link" />|
                                                    <asp:Button ID="btnDel" Text="Xóa" CommandName="cmdDel" OnClientClick="return confirm('Bạn có chắc là muốn xóa ảnh này?');"
                                                        runat="server" CssClass="btn_link" CommandArgument='<%# Eval("ID") %>' OnClick="btnDel_cLick" />
                                                </td>
                                            </tr>
                                        </table>
                                        </font>
                                    </fieldset>
                                </ItemTemplate>
                            </asp:DataList>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <div class="divPopup" id="divAddAlbum" style="<%=IsDisplay()%>">
        <div class="divPopupHeader">
            Thêm ảnh vào albumn</div>
        <div id="content" class="divPopupContent">
            <input type="file" id="File1" runat="server" />
            <br />
            <input type="file" id="File2" runat="server" />
            <br />
            <input type="file" id="File3" runat="server" />
            <br />
            <input type="file" id="File4" runat="server" />
        </div>
        <div style="position: absolute; right: 0px; bottom: 0px;">
            <asp:Button ID="btnSaveImage" CssClass="btnadmin" Text="Lưu ảnh" Width="110px" runat="server"
                OnClientClick="beforeSaveImage" OnClick="btnSaveImage_Click" />
            <input type="button" value="Chọn thêm ảnh" onclick="AddFileUploadControl();" class="btnadmin"
                style="width: 110px" />
            <input type="button" id="btnClose" value="Đóng" class="btnadmin" style="width: 110px"
                onclick="closeAddAlbum()" />
        </div>
    </div>
</asp:Content>
